//
//  MainViewController.m
//  OC-LBWeibo
//
//  Created by 李博 on 15/6/24.
//  Copyright © 2015年 libo. All rights reserved.
//

#import "MainViewController.h"
#import "HomeTableViewController.h"
#import "DiscoverTableViewController.h"
#import "MessageTableViewController.h"
#import "ProfileTableViewController.h"
#import "MainTabBar.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addChildViewControllers];
    
    //用KVC自定义tabBar替换系统tabBar
    MainTabBar *tb = [[MainTabBar alloc]init];
    [self setValue:tb forKeyPath:@"tabBar"];
    
    
    
    [tb.compoesButton addTarget:self action:@selector(compoesButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)compoesButtonClicked:(UIButton *)btn
{
    NSLog(@"%s",__func__);
}

- (void)addChildViewControllers
{

    [self addChildViewController:@"HomeTableViewController" title:@"首页" imgName:@"tabbar_home"];
    [self addChildViewController:@"MessageTableViewController" title:@"消息" imgName:@"tabbar_message_center"];
    [self addChildViewController:@"DiscoverTableViewController" title:@"发现" imgName:@"tabbar_discover"];
    [self addChildViewController:@"ProfileTableViewController" title:@"我" imgName:@"tabbar_profile"];
   
}



- (void)addChildViewController:(NSString *)vcName title:(NSString *)title imgName:(NSString *)imgName
{
    
    Class cls =  NSClassFromString(vcName);
    UIViewController *vc = [[cls alloc]init];
    //NSLog(@"%@",vc);
    
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imgName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imgName]];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    
    [self addChildViewController:nav];
}

@end
